﻿@using Kugar.AdminLte.Core.Test.Models.Home
@using Kugar.Core.ExtMethod
@using Kugar.UI.Web.AdminLTE.Enums
@using Kugar.UI.Web.AdminLTE.Helpers
@using Kugar.UI.Web.AdminLTE.PageControls.PageCommon
@using Kugar.UI.Web.AdminLTE.PageControls
@using Kugar.UI.Web.AdminLTE.PageControls.Helpers.ButtonExtMethod
@using Newtonsoft.Json.Linq

@model Model_List

@{
    WebUI.Title = "List";
    WebUI.CurrentMenuKey = "List";
}

@section Scripts{
    <script>
        $(function () {
            $("#table").on("webui_table.sort", function (e, data) {
                console.log(e, data);
            });
        });

        function cmdCallback(re) {
            console.log('cmdCallback', re);
        }

        function onModalSuccessCallback() {
            console.log('onModalSuccessCallback');
        }

        function onModalCloseCallback() {
            console.log('onModalCloseCallback');
        }

        function OnSelectedCallback(data) {
            console.log('OnSelectedCallback');
            console.log(data);
        }

        function OnShowCallback() {
            console.log('OnShowCallback');
        }

        function SelectorChanged(s) {
            //WebUIJS.Alert(s);

            var val = $(s).val();
            console.log(val);
            
            $("[name='levelTwo']").empty().append('<option value="-1">全部</option>');
            if (val === "0") {
                $("[name='levelTwo']")
                    .append('<option value="1">0_111</option>')
                    .append('<option value="2">0_222</option>')
                    .append('<option value="3">0_333</option>');
            }
            if (val === "1") {
                $("[name='levelTwo']")
                    .append('<option value="1">1_111</option>')
                    .append('<option value="2">1_222</option>')
                    .append('<option value="3">1_333</option>');
            }
            if (val === "2") {
                $("[name='levelTwo']")
                    .append('<option value="1">2_111</option>')
                    .append('<option value="2">2_222</option>')
                    .append('<option value="3">2_333</option>');
            }
            layui.form.render('select');
        }
    </script>
}

@using (var dl = WebUI.Control.DataList<TableTest>().Render())
{
    @(dl.FilterBlock.ColQty(QueryBoxColCount.Col_4).HideQueryButton().QueryButtonText("查询").QueryButtonIconCss("fa-search").QueryButtonColor(ColorPaletteEnum.info)
          .AddHiddenValue("hid", "123")

          .AddSelector(x => x.BoxItemLabel("selector").Name("levelOne").OnChangedScript("SelectorChanged(this);").Options(new[]
          {
              new SelectorItem("000", "0"),
              new SelectorItem("001", "1"),
              new SelectorItem("002", "2")
          }).FirstItem("全部", "-1").CurrentValue(2))

          .AddSelector(x => x.BoxItemLabel("selector").Name("levelTwo").FirstItem("全部", "-1").Options(new SelectorItem[0]))

          .AddCheckbox(x => x.BoxItemLabel("checkbox").Name("ckb").Checked(new[] { "1", "2" }).Options(new[]
          {
              new SelectorItem("000", "0"),
              new SelectorItem("001", "1"),
              new SelectorItem("002", "2")
          }))

          .AddDateTime(x => x.ValueLimit(DateTime.Now.AddDays(-10), DateTime.Now.AddDays(-5)).BoxItemLabel("date").Type(DatetimePickerType.Date).Name("dt").Value(null))
          .AddDateTimeRange(x => x.BoxItemLabel("daterange").ValueLimit(DateTime.Now.AddDays(-5), DateTime.Now.AddDays(5)).Type(DatetimePickerType.Date).Name("sDT", "eDT").Value(null, null))

          .AddValueRange(x => x.BoxItemLabel("valuerange").SelectedOnClick().Value("100", "200").Name("sVal", "eVal").ValueLimit(12, 0).Type(InputElementType.number))

          .AddTextBoxWithButton(x => x.BoxItemLabel("User").Value("").Name("UserName").AddItemHiddenValue("UserID", "").ShowDataPicker("/Home/DataPicker", new JObject()
          {
              {"[name='UserID']","UserID" },
              {"[name='UserName']","UserName1" }
          }).ReadOnly().ButtonType(ButtonTypeEnum.button))

          .AddTextBoxWithButton(x => x.BoxItemLabel("keyword").Name("keyword").PlaceHolder("input keyword").SelectedOnClick().ButtonType(ButtonTypeEnum.submit).ButtonText("search").ButtonIconCss(""))

          .AddTextBox(x => x.BoxItemLabel("textbox").Value("aaa").Name("txt").SelectedOnClick())
          .AddButton(x => x.Text("search").Color(ColorPaletteEnum.info).Type(ButtonTypeEnum.submit))
          
          .Render())

    using (var db = dl.DataBlock
        .AddLeftSideButton(x => x.Text("ModalList").ShowModal("/Home/ModalList").Color(ColorPaletteEnum.lazur))
        .AddLeftSideButton(x => x.Text("Index").Href("/Home/Index",LinkTargetType.Self).Color(ColorPaletteEnum.info))
        .AddRightSideButton(x => x.Text("Modal").ShowModal("/Home/ModalWindow").Color(ColorPaletteEnum.primary))
        .AddRightSideButton(x => x.Text("DataPicker").ShowDataPicker("/Home/DataPicker", "OnSelectedCallback", "OnShowCallback").Color(ColorPaletteEnum.success))
        .Render())
    {
        using (var tbl = db.Table.Data(Model.Data).ID("table").ScrollY(500).Type(DataTableTypeEnum.WebUITable).LeftFixedColumn(1).RightFixedColumn(1).FillRowCount(10).PagerShowFirstLast().NoWrap().Render())
        {
            @tbl.Columns.AddIndex()

            @tbl.Columns.AddLabel().ColumnTitle("UserName1").WithHiddenValues(x=>new []{(x.UserName1,x.UserName2)}).Value(x => x.UserName1)

            @tbl.Columns.AddLabel().ColumnTitle("UserName2").SortKey("sss").Value(x => x.UserName2)

            @tbl.Columns.AddLabel().ColumnTitle("UserName3").Value(x => x.UserName3.ToStringEx("yyyy-MM-dd"))

            @tbl.Columns.AddLabel().ColumnTitle("UserName4").Value(x => x.UserName4.ToString())

            @tbl.Columns.AddLabel().ColumnTitle("UserName5").Value(x => x.UserName5)

            @tbl.Columns.AddLabel().ColumnTitle("UserName6").Value(x => x.UserName6)

            @tbl.Columns.AddLabel().ColumnTitle("UserName7").Value(x => x.UserName7)

            @tbl.Columns.AddLabel().ColumnTitle("UserName8").Value(x => x.UserName8)

            @(tbl.Columns.AddButtonList().ColumnTitle("操作").MenuTitle("操作").ButtonType(ColumnDropdownButtonType.ButtonList).Color(ColorPaletteEnum.@default)
                  .AddButton((data, btn) => btn.Text("显示").ExecuteCmd("/Home/Operation", "show", new JObject() { { "ID", 100 } }, "cmdCallback").Color(ColorPaletteEnum.lightyellow))
                  .AddButton((data, btn) => btn.Text("删除").ExecuteCmd("/Home/Operation", "delete", new JObject() { ["ID"] = 100 }, "cmdCallback", "确定删除？").Color(ColorPaletteEnum.lavenderblush))
                  .AddButton((data, btn) => btn.Text("Index").Href("/Home/Index",LinkTargetType.Self).Color(ColorPaletteEnum.azure))
                  .AddButton((data, btn) => btn.Text("Modal").ShowModal("/Home/ModalWindow").Color(ColorPaletteEnum.lightcyan))
                  .AddButton((data, btn) => btn.Text("DataPicker").ShowDataPicker("/Home/DataPicker", "OnSelectedCallback", "OnShowCallback").Color(ColorPaletteEnum.honeydew)))
        }
    }
}